﻿@{ 
    ViewBag.Title = "拓垦";
    Layout = "~/Views/Shared/_MallLayout.cshtml";
    bool isLogin = HttpContext.Current.User.Identity.IsAuthenticated;
    var notic = ViewData["notic"] as Pay.DTO.notice_dto;
    var user_red = ViewData["user_red"] as Pay.DTO.red_user_dto;
    var red = ViewData["red"] as List<Pay.DTO.redrecorddetail_dto>;
    string site_img = ViewData["site_img"] as string;
    var token_user_info = ViewData["TokenUser"] as token_user_info;
    var adList = ViewData["new_ad_list"] as List<Pay.DTO.ad_dto>;
}
<body class="page-home">
    <div class="main">
        <!-- 流星 -->
        <div class="meteor">
            <div class="star"></div>
            <div class="star pink"></div>
            <div class="star blue"></div>
        </div>
        <div class="pagehome">
            <!-- 公告 -->
            <div class="advices">
                <div class="noticect" onclick="openView(1)">
                    <a class="noticect" tag="div" href="#">
                        <i class="voice"></i>
                        <div id="demo" class="notice" style="position: relative; left: 0;">
                            <div id="demo1"> @(notic != null ? notic.title : "")</div>
                            <div id="demo2"></div>
                        </div>
                    </a>
                </div>
                <span class="physical" tag="div">
                    <p class="diamond" onclick="openView(2)">
                        <i class="diamondico" id="cartoonend"></i>
                        <span>红钻</span>
                        <span id="redsum">@(isLogin ? user_red.present_red_drill : 0)</span>
                    </p>
                    <p class="soup" onclick="openView(3)">
                        <i class="soupico"></i>
                        <span>马力</span>
                        <span>@(isLogin ? user_red.horse_power : 0)</span>
                    </p>
                </span>
            </div>
            <!-- 红钻 -->
            <div class="stars">
                <i class="ball"></i>
                @if (isLogin) {
                    if (red != null && red.Count >= 0) {
                        if (red.Count > 0) {
                            var length = red.Count > 10 ? 10 : red.Count;
                            for (var i = 0; i < length; i++) {
                                <div class="scoop_content effective item_@(i+1)" data-id="@red[i].id">
                                    <i class="scoop"></i>
                                    <span>@red[i].red_drill</span>
                                </div>
                            }

                        } else {
                            <div class="scoop_content" style="position: absolute;top: 5.426667rem; left: 7.234667rem; text-align:center;">
                                <i class="scoop"></i>
                                <span>@(token_user_info.is_verify_no_card ? "生产中" : "需要实名")</span>
                            </div>
                        }
                    }
                } else {
                    <div class="scoop_content" style="position: absolute;top: 5.426667rem; left: 7.234667rem; text-align:center;" onclick="jumpUrl('/home/login')">
                        <i class="scoop"></i>
                        <span>登录后领取</span>
                    </div>
                }
            </div>
            <!-- 获取马力 -->
            <div class="scoop_link">
                <a tag="div" href="javascript:openView(4)">
                    <i class="agin_ico1"></i>
                    <span>获得马力</span>
                </a>
                <a tag="div" href="javascript:jumpUrl('/Consumption/ProductExchange')">
                    <i class="agin_ico2"></i>
                    <span>红钻商城</span>
                </a>
                <a href="javascript:jumpUrl('/shopinfo/ShowShop')" tag="div" class="invite">
                    <i class="agin_ico3"></i>
                    <span>节点商城</span>
                </a>
            </div>
            <div class="mining">
                <img src="~/Content/css/tokenmall/img/index/home_wakuang.gif" alt>
            </div>
        </div>
        <div class="slide_item">
            <div class="swiper-container">
                <div class="swiper-wrapper">
                    @if (adList != null && adList.Count() > 0) {
                        foreach (var ad in adList) {
                            <div class="swiper-slide">
                                <div class="item">
                                    <a href="@(ad.link_url == null ? "javascript:void(0)" : string.Format("javascript:jumpUrl('{0}')", ad.link_url))">
                                        <div class="content">
                                            <div class="rhombus">
                                                <img src="@(site_img + ad.img_url)">
                                            </div>
                                            <div class="intro">
                                                <span class="what">@ad.title</span>
                                                <span class="gary">@ad.subtitle</span>
                                            </div>
                                        </div>
                                    </a>
                                </div>
                            </div>
                        }
                    }
                </div>
                <!-- Add Pagination -->
                <!-- <div class="swiper-pagination"></div> -->
            </div>
        </div>
    </div>
    <div class="footer" style="display:none">
        <ul>
            <li>
                <a href="/Home/Index" class="router-link-active">
                    <i class="jd1hover"></i>
                    <span>基地</span>
                </a>
            </li>
            <li>
                <a href="/DistributionMall/Index">
                    <i class="jd2hover"></i>
                    <span>云商城</span>
                </a>
            </li>
            <li>
                <a href="/ProductTokenMaker/Index">
                    <i class="jd3hover"></i>
                    <span>创客导购</span>
                </a>
            </li>
            <li>
                <a href="/User/My">
                    <i class="jd4hover"></i>
                    <span>我的</span>
                </a>
            </li>
        </ul>
    </div>
    <script src="~/Scripts/tokenmall/jquery.fly.min.js"></script>
    <script src="~/Scripts/tokenmall/swiper.min.js"></script>
    <script src="~/Scripts/token-common.js"></script>
    <link rel="stylesheet" type="text/css" href="~/Content/css/tokenmall/css/swiper.min.css" media="all" />
    <script type="text/javascript">
        //点击广告，记录点击数
        function clickAd(id, url) {
            $.ajax({
                url: '@Url.Action("GetAd","Ad")',
                async: false,
                type: 'POST',
                data: { id: id },
                success: function (result) {
                    window.location.href = url;
                }
            });
        }

    </script>
    <script>
        $(function () {
            // 公告滚动
            var speed = 40;//数值越大，速度越慢

            var demo2 = document.getElementById("demo2");

            var demo1 = document.getElementById("demo1");

            var demo = document.getElementById("demo");

            function MarqueeLeft() {
                if (demo2.offsetWidth - demo.scrollLeft <= 0) demo.scrollLeft -= demo1.offsetWidth
                else { demo.scrollLeft++ }
            }

            var MyMar = setInterval(MarqueeLeft, speed);
            demo.onmouseover = function () {
                clearInterval(MyMar);
            }
            demo.onmouseout = function () {
                MyMar = setInterval(MarqueeLeft, speed);
            }

            // 轮播图配置
            var swiper = new Swiper('.swiper-container', {
                slidesPerView: 2.18,
                spaceBetween: 0,
                slidesOffsetBefore: 10,
                pagination: {
                    el: '.swiper-pagination',
                    clickable: true,
                },
            });


            // 浮点数相加
            function accAdd(arg1, arg2) {
                var r1, r2, m, c;
                try {
                    r1 = arg1.toString().split(".")[1].length;
                } catch (e) {
                    r1 = 0;
                }
                try {
                    r2 = arg2.toString().split(".")[1].length;
                } catch (e) {
                    r2 = 0;
                }
                c = Math.abs(r1 - r2);
                m = Math.pow(10, Math.max(r1, r2));
                if (c > 0) {
                    var cm = Math.pow(10, c);
                    if (r1 > r2) {
                        arg1 = Number(arg1.toString().replace(".", ""));
                        arg2 = Number(arg2.toString().replace(".", "")) * cm;
                    } else {
                        arg1 = Number(arg1.toString().replace(".", "")) * cm;
                        arg2 = Number(arg2.toString().replace(".", ""));
                    }
                } else {
                    arg1 = Number(arg1.toString().replace(".", ""));
                    arg2 = Number(arg2.toString().replace(".", ""));
                }
                return (arg1 + arg2) / m;
            }
            //点击红钻动画
            var offset = $("#cartoonend").offset();
            $(".scoop_content").click(function (event) {
                var addcar = $(this);
                var id = $(this).attr("data-id");
                if (id == null || id == undefined) {
                    return false;
                }
                var flyer = $('<div class="u-flyer"></div>');
                flyer.fly({
                    start: {
                        left: event.pageX,
                        top: event.pageY
                    },
                    end: {
                        left: offset.left - 10,
                        top: offset.top + 12,
                        width: 0,
                        height: 0
                    },
                    onEnd: function () {
                        this.destory();
                    }
                });

                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/Home/GetRed",//url
                    async: false,
                    data: { Id: id },
                    success: function (result) {
                        if (result.result_code == 1000) {
                            addcar
                                .css("display", "none")
                                .removeClass("effective")
                                .removeClass("orange")
                                .unbind("click");
                            var clicknum = $(addcar)
                                .find("span")
                                .text();
                            var redsum = $("#redsum").text();
                            $("#redsum").text(accAdd(clicknum, redsum)); //得到红钻总数量

                            if ($(".stars .effective") == undefined || $(".stars .effective").length == 0) {
                                window.location.reload();
                            }

                        }
                        else {
                            layer.msg(result.result_msg);
                        }
                        flag = false;
                    },
                    error: function () {
                        layer.msg("异常！");
                        flag = false;
                    }
                });
            });
        })
    </script>

    <script type="text/javascript">
        var browser = {
            versions: function () {
                var u = navigator.userAgent, app = navigator.appVersion;
                return {
                    //移动终端浏览器版本信息
                    trident: u.indexOf('Trident') > -1, //IE内核
                    presto: u.indexOf('Presto') > -1, //opera内核
                    webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                    gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                    mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
                    ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                    android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
                    iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
                    iPad: u.indexOf('iPad') > -1, //是否iPad
                    webApp: u.indexOf('Safari') == -1, //是否web应该程序，没有头部与底部,
                    WeiXin: u.match(/MicroMessenger/i) == "MicroMessenger" //是否为微信客户端
                };
            }(),
            language: (navigator.browserLanguage || navigator.language).toLowerCase()
        };

        $(function () {
            if (browser.versions.mobile) {
                //判断是否是移动设备打开。browser代码在下面
                var ua = navigator.userAgent.toLowerCase();
                //获取判断用的对象
                if (ua.match(/MicroMessenger/i) == "micromessenger") { //微信中打开
                    $(".footer").css('display', '');
                }
            }
        });

        function openView(type) {
            console.log(type)
            try {
                if (browser.versions.ios) {
                    window.webkit.messageHandlers.openView.postMessage(type);
                } else {
                    if (type == 1) {
                        window.location.href = '/notic/NoticeMessge';
                    } else if (type == 4) {
                        window.location.href = '/task/list';
                    }
                }
            } catch (e) {
                if (type == 1) {
                    window.location.href = '/notic/NoticeMessge';
                } else if (type == 4) {
                    window.location.href = '/task/list';
                }
            }
        }

        function jumpUrl(url) {
            console.log(url)
            try {
                if (browser.versions.ios) {
                    if (url == '/home/login') {
                        window.webkit.messageHandlers.loginAction.postMessage('');
                    } else {
                        window.webkit.messageHandlers.jumpUrl.postMessage(url);
                    }
                } else {
                        window.location.href = url;
                }
            } catch (e) {
                window.location.href = url
            }


        }


    </script>
</body>
